package com.woniu.service;

import com.woniu.adapter.GoldAdapter;
import com.woniu.outlet.elasticSearch.po.Gold;
import com.woniu.outlet.mysql.po.GoldMysql;
import com.woniu.outlet.redis.po.GoldRela;
import com.woniu.service.goldcommand.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description:
 * @author: my
 * @time: 2021/4/22 19:46
 */
@Slf4j
@Service
public class GoldService implements GoldDetailCommandHandler, GoldsCommandHandler ,
        GoldGraphCommandHandler,GetAllGoldCommandHandler {

    private GoldAdapter goldAdapter;

    public GoldService(GoldAdapter goldAdapter){
        this.goldAdapter = goldAdapter;
    }

    @Override
    public Gold action(GoldDetailCommand goldDetailCommand) throws Exception {
        String type = goldDetailCommand.getType();
        log.debug(type);
        return goldAdapter.getGoldDetail(type);
    }


    @Override
    public List<GoldRela> action(GoldsCommand goldCommand) throws Exception {
        return goldAdapter.getGolds();
    }

    @Override
    public List<GoldMysql> action(GoldGraphCommand command) {
        String type = command.getType();
        Integer month = command.getMonth();
        return goldAdapter.getGoldGraph(type,month);
    }

    /**
     * 获取所有黄金信息
     * @param command
     * @return
     */
    @Override
    public List<Gold> action(GetAllGoldCommand command) {
        return goldAdapter.getAllGold();
    }
}
